package com.hopu.aop.util;

import org.aspectj.lang.ProceedingJoinPoint;

/**
 * 日志通知类，添加日志功能
 */
public class LogAdvise {

    public void beforeLog(){
        System.out.println("这是前置的日志！");
    }

    public void afterLog(){
        System.out.println("这是后置的日志！");
    }

    public void afterReturning(){
        System.out.println("这是方法返回后执行的！");
    }

    public void afterThrowing(Throwable ex){
        System.out.printf("这是方法抛异常了！！" + ex.getMessage());
    }

    public Object around(ProceedingJoinPoint point) throws Throwable {
        String name = point.getSignature().getName();
        Object[] args = point.getArgs();
        System.out.println("=====开始执行"+name);
        System.out.println("传入参数：");
        for(Object arg : args){
            System.out.println(arg);
        }
        long start = System.currentTimeMillis();
        //执行方法
        Object result = point.proceed();
        long end = System.currentTimeMillis();
        System.out.println("=====结束执行"+name+",耗时：" + (end - start));
        System.out.println("返回值:" + result);
        return result;
    }
}
